interface IAuthType {
  token: string;
  refresh_token: string;
}

// 常量 token的key
const TOKEN_KEY = "itcast-geek-park-h5";

// 获token
export const getAuth = (): IAuthType => {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || "{}");
};

// 存token
export const saveAuth = (tokenInfo: IAuthType) => {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(tokenInfo));
};

// 删除token
export const removeAuth = () => {
  localStorage.removeItem(TOKEN_KEY);
};

// 判断有没有token
export const hasToken = () => {
  return !!getAuth().token;
};
